package cn.itcast.bos.action.system;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.domain.system.Role;
import cn.itcast.bos.service.system.RoleService;
import cn.itcast.fore.web.action.common.BaseAction;

@Controller
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class RoleAction extends BaseAction<Role> {
	@Autowired
	private RoleService roleService;

	@Action("role_list")
	public String list() {
		List<Role> roleList = roleService.findByRole();
		// 压入root栈顶
		ActionContext.getContext().getValueStack().push(roleList);
		return JSON;

	}

	// 属性驱动封装两个参数
	private String[] permissionIds;
	private String menuIds;

	public void setPermissionIds(String[] permissionIds) {
		this.permissionIds = permissionIds;
	}

	public void setMenuIds(String menuIds) {
		this.menuIds = menuIds;
	}

	// 保存
	@Action(value = "role_add", results = { @Result(type = "redirect", location = "/pages/system/role.html") })
	public String add() {
		roleService.saveRole(model, permissionIds, menuIds);

		return SUCCESS;
	}

}
